package com.exposit.books.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.exposit.books.dao.OrderDAO;
import com.exposit.books.domain.Book;
import com.exposit.books.domain.Order;

@Service
@Transactional
public class PreOrderServiceImpl implements PreOrderService {

	//@Autowired
	private OrderDAO orderDAO;
	
	@Override
	public List<Order> getAllPreOrders() {
		// TODO Auto-generated method stub
		List <Order> preorder = new ArrayList <Order>();
		List<Order> order = orderDAO.getAll();
		Book bookprice = new Book();
		Order ordercount = new Order();
		for(Order entry: order) {
			
		if (entry.getStatus() == -2L) {
			
			if(ordercount.getCount() > 10L){
				entry.setPublishPrice(bookprice.getPurchasePrice()-bookprice.getPurchasePrice()*3/100);
				
			}
			else entry.setPublishPrice(bookprice.getPurchasePrice());
			entry.setStatus(-3L);
			preorder.add(entry);
			
		}
		return preorder;
	    }
		return null;
	}

	@Override
	public void updateOrder(Order order) {
		// TODO Auto-generated method stub
		orderDAO.update(order);
		
	}

}
